<?
//include "libchart/classes/libchart.php";
switch($act){
	case 'vote':
		Vote();
		$tpl = 'show';
		break;

	default:
		global $title_bar;
		$title_bar =  "Kết quả tìm kiếm";
		$tpl="result";
		break;
}
function Vote()
{
	global $db, $votes, $title_bar, $arrColor, $question, $total;
	$title_bar = "Bầu chọn";
	if(!isset($_SESSION['isVoted'])){
		if(isset($_POST['vote'])){
			$sql = "update votes set voted=voted+1 where id=". $_POST['vote'];
			$r = $db->query($sql);
			session_register("isVoted");
			$_SESSION['isVoted'] = 1;
		}
	}
	$sql="select * from votes where cid=".$_GET['cid']." and is_question=1 order by ordering asc, id asc ";	
	$r = $db->getRow($sql);
	$question = $r["name_" . $_SESSION['lg']];

	$sql="select * from votes where cid=".$_GET['cid']." and is_question<>1 order by voted desc, ordering asc, id asc ";	
	$votes = $db->getAll($sql);
	$arrColor = array('#FF3300', '#004000', '#004080', '#FF0080', '#008080', '#a89395', '#28ab35', '#8b4617', '#6d74ba', '#21cbc9','#000','#fff000');
	$total = 0;
	if($votes){
		foreach($votes as $vote){	
			$total += $vote['voted'];
		}
	}
		
	/*$chart = new VerticalBarChart(600,600);

	$dataSet = new XYDataSet();
	if($votes){
		foreach($votes as $vote){
			$str = $vote["name_".$_SESSION['lg']];
			//$str = substr($str, strpos( $str," ", 13));
			$str = StripUnicode($str);
			$dataSet->addPoint(new Point($str, $vote['voted']));
		}
	}
	$chart->setDataSet($dataSet);

	$chart->setTitle("");
	$chart->render("upload/images/demo1.png");*/
}
?>